package com.xinziruo.richclient.util.filecommand.impl;

import java.io.File;

import org.apache.commons.io.FileUtils;

import com.xinziruo.richclient.util.ExceptionUtils;
import com.xinziruo.richclient.util.filecommand.FileCommand;

/**
 * 
 * @author loudyn
 * 
 */
public class WriteBytesToFileCommand implements FileCommand {
	private final File target;
	private final byte[] content;

	public WriteBytesToFileCommand(File target, byte[] content) {
		this.target = target;
		this.content = content;
	}

	public WriteBytesToFileCommand(String target, byte[] content) {
		this(new File(target), content);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.youboy.module.util.filecommand.FileCommand#execute()
	 */
	public void execute() {
		try {

			FileUtils.writeByteArrayToFile(target, content);
		} catch (Exception e) {
			throw ExceptionUtils.toUnchecked(e);
		}
	}

}
